package com.zhts.oa.department.entity;

import com.google.common.collect.Lists;
import lombok.Data;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

@Data
@ToString(callSuper = true)
public class DeptTree extends Department {

    private List<DeptTree> deptTrees = Lists.newArrayList();
    /**
     * 适配器，传入一个department转为相应的树结构
     */
    public static DeptTree adpt(Department dept){
        DeptTree deptTree = new DeptTree();
        BeanUtils.copyProperties(dept,deptTree);
        return deptTree;
    }

    public static List<DeptTree> adpt(List<Department> departments){
        List<DeptTree> deptTrees = new ArrayList<>();
        departments.forEach(department -> {
            DeptTree dt = adpt(department);
            deptTrees.add(dt);
        });
        return deptTrees;
    }
}
